home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / MyMovies.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  3.5 KB  |  119 lines  |  [TEXT/MPCC]

  1. #include "QD3DtoQTVR.h"
  2. #include "extern.h"
  3. #include "MyMovies.h"
  4.  
  5.  
  6.  
  7. OSErr    MyPrepareDestMovie(DocumentPtr theDocument)
  8. {
  9.     long                keyFrameRate,compressedFrameSize;
  10.     short                frameRate,width,height,i;
  11.     CodecComponent        theCodec;
  12.     OSErr                err;
  13.     FSSpec                 theFSSpec;
  14.     TimeScale            dstTimeScale;
  15.     TimeValue            duration;
  16.     CodecQ                spatialQuality;
  17.     Str255                movieName = "\p.mov";
  18.     
  19.     keyFrameRate = 1;            // Every frame must be a key frame.  If not we'll get garbage
  20.                                 // around the edges of our objects when we rotate them.  Quicktime
  21.                                 // only refreshes key frames completely.
  22.     theCodec = anyCodec;                // We'll use what's there
  23.     spatialQuality = codecHighQuality;    // and make it pretty.
  24.     frameRate = 10;                // This can be any value.
  25.     dstTimeScale = 600;            // This can be any multiple of framerate
  26.     duration = 60;
  27.     
  28.     width = theDocument->theWindow->portRect.right - theDocument->theWindow->portRect.left;
  29.     height = theDocument->theWindow->portRect.bottom - theDocument->theWindow->portRect.top;
  30.     
  31.     theFSSpec = theDocument->theFileSpec;
  32.     for(i = 1; i <= movieName[0];i++)
  33.         theFSSpec.name[i+theFSSpec.name[0]] = movieName[i];
  34.     theFSSpec.name[0] += 4;
  35.     
  36.     err = CreateMovieFile(&theFSSpec, 'TVOD', 0, createMovieFileDeleteCurFile,
  37.             &theDocument->dstMovieRefNum, &theDocument->dstMovie);
  38.     if (err)
  39.         return err;
  40.         
  41.     theDocument->dstTrack = NewMovieTrack(theDocument->dstMovie,
  42.             ((long)width) << 16, ((long)height) << 16, 0);
  43.     theDocument->dstMedia = NewTrackMedia(theDocument->dstTrack,
  44.             VideoMediaType, dstTimeScale, 0, 0);
  45.     err = BeginMediaEdits(theDocument->dstMedia);
  46.     if (err)
  47.         return err;
  48.         
  49.     err = GetMaxCompressionSize(theDocument->drawContextOffscreen->portPixMap,
  50.             &theDocument->drawContextOffscreen->portRect, 32, spatialQuality,
  51.             theDocument->theCodecType, theCodec, &compressedFrameSize);
  52.     if (err)
  53.         return err;
  54.         
  55.     theDocument->compressedData = NewHandle(compressedFrameSize);
  56.     theDocument->compressedDataPtr = StripAddress(*(theDocument->compressedData));
  57.     HLock(theDocument->compressedData);
  58.     theDocument->idh = (ImageDescriptionHandle)NewHandle(4); 
  59.     
  60.     return err;    
  61. }
  62.  
  63.     
  64. OSErr    MyAddImageToMovie(DocumentPtr theDocument)
  65. {
  66.     CodecQ                spatialQuality;
  67.     TimeValue            duration,currentTime;
  68.     OSErr                err;
  69.     
  70.     spatialQuality = codecHighQuality;
  71.     duration = 60;
  72.     
  73.     LockPixels(theDocument->drawContextOffscreen->portPixMap);
  74.     CompressImage(theDocument->drawContextOffscreen->portPixMap,
  75.             &theDocument->drawContextOffscreen->portRect,spatialQuality,
  76.             theDocument->theCodecType,theDocument->idh,theDocument->compressedDataPtr);
  77.     UnlockPixels(theDocument->drawContextOffscreen->portPixMap);
  78.             
  79.     err = AddMediaSample(theDocument->dstMedia,theDocument->compressedData,0,
  80.             (**(theDocument->idh)).dataSize,duration,
  81.             (SampleDescriptionHandle)theDocument->idh,1,0,¤tTime);
  82.     
  83.     return err;
  84. }
  85.  
  86. void    MyCloseDestMovie(DocumentPtr theDocument)
  87. {
  88.     OSErr    err;
  89.     short    resID;
  90.     
  91.     err = EndMediaEdits(theDocument->dstMedia);
  92.     if (err)
  93.         goto cleanup;
  94.         
  95.     InsertMediaIntoTrack(theDocument->dstTrack,0,0,
  96.             GetMediaDuration(theDocument->dstMedia),1L<<16);
  97.     err = GetMoviesError();
  98.     if (err)
  99.         goto cleanup;
  100.         
  101.     resID = 128;
  102.     err = AddMovieResource(theDocument->dstMovie,theDocument->dstMovieRefNum,
  103.             &resID,(unsigned char *)"\pMovie 1");
  104.  
  105. cleanup:    
  106.     if (theDocument->compressedData) {
  107.         HUnlock((Handle)theDocument->compressedData);
  108.         DisposeHandle(theDocument->compressedData);
  109.     }
  110.     
  111.     if (theDocument->dstMovieRefNum)
  112.         CloseMovieFile(theDocument->dstMovieRefNum);
  113.     
  114.     if (theDocument->dstMovie)
  115.         DisposeMovie(theDocument->dstMovie);
  116.     
  117.     if (theDocument->idh)
  118.         DisposeHandle((Handle)theDocument->idh);
  119. }